/**
 * 
 */
package com.daogou.jdbc.connection;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * @author jianwen
 *
 */
public class JDBCConnection {
	private String driveClass = "com.mysql.jdbc.Driver";
	private String url = "jdbc:mysql://localhost:3306/daogou?useUnicode=true&characterEncoding=utf8";
	private String username = "root";
	private String pass = "123456";
	/**
	 * 获取连接
	 * @return
	 * @throws SQLException 
	 * @throws ClassNotFoundException 
	 */
	
	public Connection getConection() throws SQLException, ClassNotFoundException{
		try {
			//注册驱动
			Class.forName(driveClass);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			throw e;
		}
		
	  return DriverManager.getConnection(url, username, pass);
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		JDBCConnection conn = new JDBCConnection();
		try {
			conn.getConection();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
